package study.day7;

import java.io.*;

public class T8 {
    //二进制读写
    public static void main(String[] args) {
        //DataInputStream DataOutPutStream读写
        FileInputStream fis = null;
        FileOutputStream fos = null;
        DataInputStream dis = null;
        DataOutputStream dos = null;
        try {
            //源文件路径
            fis=new FileInputStream("C:\\Users\\DELL\\IdeaProjects\\file\\1.jpg");
            //目标文件路径
            fos=new FileOutputStream("C:\\Users\\DELL\\IdeaProjects\\file\\123.jpg");
            dis=new DataInputStream(fis);
            dos=new DataOutputStream(fos);
            //边读边写
            int data;
            while((data=dis.read())!=-1){
                dos.write(data);
            }
            System.out.println("写入成功");
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
        }catch (IOException e){
            e.printStackTrace();
        }finally{
            try {
                dos.close();
                dis.close();
                fos.close();
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
